# -*- coding: utf-8 -*-
# @Time    : 2022/5/25 11:14
# @Author  : leijiu
# @Email   : 517711635@qq.com
# @File    : goods_type_list_page.py
# @Software: PyCharm
"""
商品类型列表页面
"""
from selenium.webdriver.common.by import By
from time import sleep

class GoodsTypeList():
    def __init__(self, driver):
        self.driver = driver

    # 商品类型定位器
    ele_goodsadmin_locator = (By.CSS_SELECTOR, "#menu-ul > li.collapse.lis.ico_1")
    ele_goodstype_locator = (By.LINK_TEXT, "商品类型")
    ele_addgoodstye_locator = (By.LINK_TEXT, "新建商品类型")
    # 编辑定位器
    ele_goodstyeedit_locator = (By.CSS_SELECTOR, "#listTable > tbody > tr:nth-child(2) > td:nth-child(5) > a:nth-child(2)")
    # 删除定位器
    ele_goodstyeedelete_locator = (By.CSS_SELECTOR, "#listTable > tbody > tr:nth-child(2) > td:nth-child(5) > a:nth-child(3)")

 # 页面切换
    def leftpage(self):
        self.driver.switch_to.frame("menu-frame")
        sleep(1)
        # 点击商品管理
    def goodsadmin(self):
        self.driver.find_element(*self.ele_goodsadmin_locator).click()
        sleep(1)
        # 点击商品类型
    def goodstype(self):
        self.driver.find_element(*self.ele_goodstype_locator).click()
        sleep(1)
        # 切换到主页面
    def mainpage(self):
        self.driver.switch_to.parent_frame()
        self.driver.switch_to.frame("main-frame")
        sleep(1)
        # 点击添加商品类型
    def addgoodstye(self):
        self.driver.find_element(*self.ele_addgoodstye_locator).click()
        # 编辑类型
    def goodstyeedit(self):
        self.driver.find_element(*self.ele_goodstyeedit_locator).click()
        #删除类型
    def goodstyedelete(self):
        self.driver.find_element(*self.ele_goodstyeedelete_locator).click()
        self.driver.switch_to.alert.accept()
    def classad(self):
        return self.driver.find_element(By.CSS_SELECTOR,"#totalRecords").text